//
//  ZhiYuanGuanLiRootViewController.m
//  YaoHeAPP
//
//  Created by 杨亚森 on 16/7/6.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ZhiYuanGuanLiRootViewController.h"
#import "Masonry.h"
#import "ShenQingJiaRuViewController.h"
#import "peopleVC.h"

@interface ZhiYuanGuanLiRootViewController ()
{
    NSMutableArray*_ary;
    UIView *_navcBar;
    NSMutableArray*_dataArray;//数据源数组
    
}
@property(nonatomic,strong) peopleVC *peopleController;
@property(nonatomic,strong) ShenQingJiaRuViewController *shenQingJiaRuViewController;
@property(nonatomic,strong) UIView *peopleView;
@property(nonatomic,strong) UIView *ShenQingJiaRuView;

@end

@implementation ZhiYuanGuanLiRootViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"peopleVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"peopleVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor=bgVCcolor;
    //加一个导航条
    _navcBar=[[UIView alloc]init];
    _navcBar.backgroundColor=[UIColor colorWithRed:90.f/255.f green:191.f/255.f blue:219.f/255.f alpha:1];
    [self.view addSubview:_navcBar];
    [self.view bringSubviewToFront:_navcBar];
    [_navcBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);   make.left.offset(0);
        make.height.offset(100);  make.right.offset(0);
    }];
    //导航条标题
    UILabel*titleLabel=[[UILabel alloc]init];
    titleLabel.text=@"职员管理";
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[UIColor whiteColor];
    [_navcBar addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25);
        make.left.offset(self.view.frame.size.width/2-50);
        make.width.offset(100);
        make.height.offset(30);
    }];
    
    //返回按钮
    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backUp) forControlEvents:UIControlEventTouchUpInside];
    [_navcBar addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(6);
        make.width.offset(30);
        make.height.offset(28);
        make.top.offset(25);
    }];
    
    
    //右侧加入公司按钮
    UIButton*rightButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setTitle:@"+邀请职员" forState:UIControlStateNormal];
    rightButton.titleLabel.font=Font(14);
    [rightButton addTarget:self action:@selector(jionpeople) forControlEvents:UIControlEventTouchUpInside];
    [_navcBar addSubview:rightButton];
    [rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-6);
        make.width.offset(100);
        make.height.offset(28);
        make.top.offset(25);
    }];
    
    
    NSArray *segmentItemsArray = [NSArray arrayWithObjects:@"已加入", @"申请加入", nil];
    UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:segmentItemsArray];
    segmentControl.frame = CGRectMake(10, 64, self.view.width-20, 30);
    segmentControl.tintColor = RGBCOLOR(109, 205, 226);
    segmentControl.selectedSegmentIndex = 0;
    [segmentControl addTarget:self action:@selector(segmentAction:)forControlEvents:UIControlEventValueChanged];
    [_navcBar addSubview:segmentControl];
    
    //修改字体的默认颜色与选中颜色
    NSDictionary *dic = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:16.f],
                          NSForegroundColorAttributeName: [UIColor whiteColor]};
    [segmentControl setTitleTextAttributes:dic forState:UIControlStateSelected];
    
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:16.f],
                                               NSForegroundColorAttributeName: [UIColor lightTextColor]};
    [segmentControl setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    segmentControl.layer.masksToBounds = YES;
    segmentControl.layer.cornerRadius = 15;
    segmentControl.layer.borderWidth = 2;
    segmentControl.layer.borderColor = RGBCOLOR(120, 205, 226).CGColor;
    
    //已加入的view
    _peopleController = [[peopleVC alloc] init];
    self.peopleView = _peopleController.view;
    
    [self.peopleView willMoveToSuperview:self.view];
    self.peopleView.frame=CGRectMake(0, 100, SCREEN_WIDTH, SCREEN_HEIGHT-100);
    [self.view addSubview:self.peopleView];
    [self.peopleView didMoveToSuperview];
    [self addChildViewController:_peopleController];
    
    _shenQingJiaRuViewController = [[ShenQingJiaRuViewController alloc] init];
    self.ShenQingJiaRuView = _shenQingJiaRuViewController.view;
    [self addChildViewController:_shenQingJiaRuViewController];

    

}
-(void)jionpeople
{
    
    [MobClick event:@"inviteStaff"];
    
    NSString *ret=[NSString stringWithFormat:@"请将公司的邀请码复制一份发给职员，您可通过QQ、微信、短信等聊天软件发送。\n邀请码:%@",self.compayid];
    //初始化AlertView
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"邀请职员："
                                                    message:ret
                                                   delegate:self
                                          cancelButtonTitle:@"取消"
                                          otherButtonTitles:@"复制",nil];
    
    alert.alertViewStyle=UIAlertViewStyleDefault;
    //这个属性继承自UIView，当一个视图中有多个AlertView时，可以用这个属性来区分
    alert.tag = 1;
    
    [alert show];
    
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==1) {
        if (buttonIndex==1) {
            //将字符串复制到粘贴板
            NSString *st=[NSString stringWithFormat:@"%@",self.compayid];
            [UIPasteboard generalPasteboard].string =st;
            
            ALERTSHOW(@"复制成功");
            
        }else if(buttonIndex==0){
            //取消
            
            
        }
        
    }
}

#pragma mark 具体委托方法
- (void)segmentAction:(UISegmentedControl *)segmentedControl {
    NSInteger index = segmentedControl.selectedSegmentIndex;
    switch (index) {
        case 0:
        {
            [self.ShenQingJiaRuView removeFromSuperview];
            [self.peopleView willMoveToSuperview:self.view];
            self.peopleView.frame=CGRectMake(0, 100, SCREEN_WIDTH, SCREEN_HEIGHT-100);
            [self.view addSubview:self.peopleView];
            [self.peopleView didMoveToSuperview];
            
        }
            break;
        case 1:
        {
            [self.peopleView removeFromSuperview];
            [self.ShenQingJiaRuView willMoveToSuperview:self.view];
            self.ShenQingJiaRuView.frame=CGRectMake(0, 100, SCREEN_WIDTH, SCREEN_HEIGHT-100);
            [self.view addSubview:self.ShenQingJiaRuView];
            [self.ShenQingJiaRuView didMoveToSuperview];

        }
            break;
        default:
            break;
    }
}




//返回上个界面
-(void)backUp
{
    [self.navigationController popViewControllerAnimated:YES];
}


@end
